package com.woniu.market_stall.mapper;

import com.github.pagehelper.PageInfo;
import com.woniu.market_stall.entity.Order;
import com.woniu.market_stall.vo.AuctionOrderVo;
import com.woniu.market_stall.vo.RentOrderVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Order record);

    Order selectByPrimaryKey(Integer id);

    List<Order> selectAll();

    int updateByPrimaryKey(Order record);

    List<RentOrderVo> selectRentOrderByOrderIdAndStatus(@Param("orderId") String orderId, @Param("statusPay") Integer statusPay);

    List<AuctionOrderVo> selectAuctionOrderByOrderIdAndStatus(@Param("orderId") String orderId,@Param("statusPay") Integer statusPay);

    @Select("select * from p_order where order_id=#{orderId}")
    Order selectRentOrderByOrderId(Long orderId);

    @Update("update p_order set is_delete=1 where order_id=#{orderId}")
    void deleteOrderById(String orderId);

    @Update("update p_order set market_id=#{marketId},stall_id=#{stallId},user_id=#{userId},order_price=#{orderPrice},status_pay=#{statusPay} where order_id=#{orderId}")
    void updateRentOrderByOrderId(Order order);

    @Insert("insert into p_order (order_id, market_id,stall_id, user_id, type, order_price, status_pay,insert_time, is_delete,contract) values(#{orderId}, #{marketId},#{stallId}, #{userId},#{type}, #{orderPrice}, #{statusPay},#{insertTime}, #{isDelete},#{contract})")
    void insertRentOrder(Order order);

    @Select("select * from p_order where order_id=#{orderId}")
    Order selectAuctionOrderByOrderId(Long orderId);

    @Update("update p_order set market_id=#{marketId},stall_id=#{stallId},user_id=#{userId},order_price=#{orderPrice},status_pay=#{statusPay},cash=#{cash} where order_id=#{orderId}")
    void updateAuctionOrderByOrderId(Order order);

    @Insert("insert into p_order (order_id, market_id,stall_id, user_id, type, order_price, status_pay,insert_time, is_delete,cash,contract) values(#{orderId}, #{marketId},#{stallId}, #{userId},#{type}, #{orderPrice}, #{statusPay},#{insertTime}, #{isDelete},#{cash},#{contract})")
    void insertAuctionOrder(Order order);


    List<Order> selectContractByPage(String contract);
}